//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "SabrInterpolatedSmileSection.h"
using namespace Cephei::QL::Termstructures::Volatility;
#include <gen/QL/Math/Optimization/EndCriteria.h>
#include <gen/QL/Math/Optimization/OptimizationMethod.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Termstructures/Volatility/SmileSection.h>
using namespace Cephei::QL::Math::Optimization;
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (DateTime optionDate, Double forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Double atmVolatility, Cephei::IVector<Double>^ vols, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc) : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
    CoVector<Double>^ _Cstrikes;
    CoVector<Double>^ _Cvols;
    CEndCriteria^ _CendCriteria;
    COptimizationMethod^ _Cmethod;
    CDayCounter^ _Cdc;
    try
    {
#ifdef HANDLE
        _phSabrInterpolatedSmileSection = NULL;
#endif
        QuantLib::Date _optionDate = (QuantLib::Date)ValueHelper::Convert (optionDate);
        QuantLib::Rate _forward = (QuantLib::Rate)ValueHelper::Convert (forward);
        CoVector<Double>^ _Cstrikes = safe_cast<CoVector<Double>^> (strikes);
        _Cstrikes->Lock();
        INativeVector<Double>^ _NCIstrikes = _Cstrikes->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCstrikes = safe_cast<CDoubleVector^>(_NCIstrikes);
        std::vector<QuantLib::Rate>& _strikes = static_cast<std::vector<QuantLib::Rate>&> (_NCstrikes->GetReference ());
        bool _hasFloatingStrikes = (bool)ValueHelper::Convert (hasFloatingStrikes);
        QuantLib::Volatility _atmVolatility = (QuantLib::Volatility)ValueHelper::Convert (atmVolatility);
        CoVector<Double>^ _Cvols = safe_cast<CoVector<Double>^> (vols);
        _Cvols->Lock();
        INativeVector<Double>^ _NCIvols = _Cvols->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCvols = safe_cast<CDoubleVector^>(_NCIvols);
        std::vector<QuantLib::Volatility>& _vols = static_cast<std::vector<QuantLib::Volatility>&> (_NCvols->GetReference ());
        QuantLib::Real _alpha = (QuantLib::Real)ValueHelper::Convert (alpha);
        QuantLib::Real _beta = (QuantLib::Real)ValueHelper::Convert (beta);
        QuantLib::Real _nu = (QuantLib::Real)ValueHelper::Convert (nu);
        QuantLib::Real _rho = (QuantLib::Real)ValueHelper::Convert (rho);
        bool _isAlphaFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isAlphaFixed) ? (bool)ValueHelper::Convert (isAlphaFixed->Value) : false); //4
        bool _isBetaFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isBetaFixed) ? (bool)ValueHelper::Convert (isBetaFixed->Value) : false); //4
        bool _isNuFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isNuFixed) ? (bool)ValueHelper::Convert (isNuFixed->Value) : false); //4
        bool _isRhoFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isRhoFixed) ? (bool)ValueHelper::Convert (isRhoFixed->Value) : false); //4
        bool _vegaWeighted = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (vegaWeighted) ? (bool)ValueHelper::Convert (vegaWeighted->Value) : true); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>::IsSome::get (endCriteria))
        {
            _CendCriteria = safe_cast<CEndCriteria^> (endCriteria->Value);
            _CendCriteria->Lock();
        }
        boost::shared_ptr<QuantLib::EndCriteria>& _endCriteria = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>::IsSome::get (endCriteria) ? static_cast<boost::shared_ptr<QuantLib::EndCriteria>&> (_CendCriteria->GetShared ()) : boost::shared_ptr<QuantLib::EndCriteria>()); //1
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>::IsSome::get (method))
        {
            _Cmethod = safe_cast<COptimizationMethod^> (method->Value);
            _Cmethod->Lock();
        }
        boost::shared_ptr<QuantLib::OptimizationMethod>& _method = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>::IsSome::get (method) ? static_cast<boost::shared_ptr<QuantLib::OptimizationMethod>&> (_Cmethod->GetShared ()) : boost::shared_ptr<QuantLib::OptimizationMethod>()); //1
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dc))
        {
            _Cdc = safe_cast<CDayCounter^> (dc->Value);
            _Cdc->Lock();
        }
        QuantLib::DayCounter& _dc = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dc) ? static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()) : QuantLib::Actual365Fixed()); //1
        _ppSabrInterpolatedSmileSection = new boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection> (new QuantLib::SabrInterpolatedSmileSection ( _optionDate,  _forward,  _strikes,  _hasFloatingStrikes,  _atmVolatility,  _vols,  _alpha,  _beta,  _nu,  _rho,  _isAlphaFixed,  _isBetaFixed,  _isNuFixed,  _isRhoFixed,  _vegaWeighted,  _endCriteria,  _method,  _dc ));
        SetSmileSection (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cstrikes != nullptr) _Cstrikes->Unlock();
        if (_Cvols != nullptr) _Cvols->Unlock();
        if (_CendCriteria != nullptr) _CendCriteria->Unlock();
        if (_Cmethod != nullptr) _Cmethod->Unlock();
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (DateTime optionDate, Cephei::QL::IQuote^ forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Cephei::QL::IQuote^ atmVolatility, Cephei::IVector<Cephei::QL::IQuote^>^ volHandles, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc) : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
    CQuote^ _Cforward;
    CoVector<Double>^ _Cstrikes;
    CQuote^ _CatmVolatility;
    CoVector<Cephei::QL::IQuote^>^ _CvolHandles;
    CEndCriteria^ _CendCriteria;
    COptimizationMethod^ _Cmethod;
    CDayCounter^ _Cdc;
    try
    {
#ifdef HANDLE
        _phSabrInterpolatedSmileSection = NULL;
#endif
        QuantLib::Date _optionDate = (QuantLib::Date)ValueHelper::Convert (optionDate);
        _Cforward = safe_cast<CQuote^> (forward);
        _Cforward->Lock();
        Handle<QuantLib::Quote>& _forward = static_cast<Handle<QuantLib::Quote>&> (_Cforward->GetHandle ()); 
        CoVector<Double>^ _Cstrikes = safe_cast<CoVector<Double>^> (strikes);
        _Cstrikes->Lock();
        INativeVector<Double>^ _NCIstrikes = _Cstrikes->getFeature (NativeFeature::Value);
        CDoubleVector^ _NCstrikes = safe_cast<CDoubleVector^>(_NCIstrikes);
        std::vector<QuantLib::Rate>& _strikes = static_cast<std::vector<QuantLib::Rate>&> (_NCstrikes->GetReference ());
        bool _hasFloatingStrikes = (bool)ValueHelper::Convert (hasFloatingStrikes);
        _CatmVolatility = safe_cast<CQuote^> (atmVolatility);
        _CatmVolatility->Lock();
        Handle<QuantLib::Quote>& _atmVolatility = static_cast<Handle<QuantLib::Quote>&> (_CatmVolatility->GetHandle ()); 
        _CvolHandles = safe_cast<CoVector<Cephei::QL::IQuote^>^> (volHandles);
        _CvolHandles ->Lock ();
        INativeVector<Cephei::QL::IQuote^>^ _NCIvolHandles = _CvolHandles->getFeature (NativeFeature::Handle);
        CQuoteVector^ _NCvolHandles = safe_cast<CQuoteVector^>(_NCIvolHandles);
        std::vector<Handle<QuantLib::Quote> >& _volHandles = static_cast<std::vector<Handle<QuantLib::Quote> >&> (_NCvolHandles->GetHandle ());
        QuantLib::Real _alpha = (QuantLib::Real)ValueHelper::Convert (alpha);
        QuantLib::Real _beta = (QuantLib::Real)ValueHelper::Convert (beta);
        QuantLib::Real _nu = (QuantLib::Real)ValueHelper::Convert (nu);
        QuantLib::Real _rho = (QuantLib::Real)ValueHelper::Convert (rho);
        bool _isAlphaFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isAlphaFixed) ? (bool)ValueHelper::Convert (isAlphaFixed->Value) : false); //4
        bool _isBetaFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isBetaFixed) ? (bool)ValueHelper::Convert (isBetaFixed->Value) : false); //4
        bool _isNuFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isNuFixed) ? (bool)ValueHelper::Convert (isNuFixed->Value) : false); //4
        bool _isRhoFixed = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (isRhoFixed) ? (bool)ValueHelper::Convert (isRhoFixed->Value) : false); //4
        bool _vegaWeighted = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (vegaWeighted) ? (bool)ValueHelper::Convert (vegaWeighted->Value) : true); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>::IsSome::get (endCriteria))
        {
            _CendCriteria = safe_cast<CEndCriteria^> (endCriteria->Value);
            _CendCriteria->Lock();
        }
        boost::shared_ptr<QuantLib::EndCriteria>& _endCriteria = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>::IsSome::get (endCriteria) ? static_cast<boost::shared_ptr<QuantLib::EndCriteria>&> (_CendCriteria->GetShared ()) : boost::shared_ptr<QuantLib::EndCriteria>()); //1
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>::IsSome::get (method))
        {
            _Cmethod = safe_cast<COptimizationMethod^> (method->Value);
            _Cmethod->Lock();
        }
        boost::shared_ptr<QuantLib::OptimizationMethod>& _method = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>::IsSome::get (method) ? static_cast<boost::shared_ptr<QuantLib::OptimizationMethod>&> (_Cmethod->GetShared ()) : boost::shared_ptr<QuantLib::OptimizationMethod>()); //1
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dc))
        {
            _Cdc = safe_cast<CDayCounter^> (dc->Value);
            _Cdc->Lock();
        }
        QuantLib::DayCounter& _dc = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dc) ? static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()) : QuantLib::Actual365Fixed()); //1
        _ppSabrInterpolatedSmileSection = new boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection> (new QuantLib::SabrInterpolatedSmileSection ( _optionDate,  _forward,  _strikes,  _hasFloatingStrikes,  _atmVolatility,  _volHandles,  _alpha,  _beta,  _nu,  _rho,  _isAlphaFixed,  _isBetaFixed,  _isNuFixed,  _isRhoFixed,  _vegaWeighted,  _endCriteria,  _method,  _dc ));
        SetSmileSection (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cforward != nullptr) _Cforward->Unlock();
        if (_Cstrikes != nullptr) _Cstrikes->Unlock();
        if (_CatmVolatility != nullptr) _CatmVolatility->Unlock();
        if (_CvolHandles != nullptr) _CvolHandles->Unlock();
        if (_CendCriteria != nullptr) _CendCriteria->Unlock();
        if (_Cmethod != nullptr) _Cmethod->Unlock();
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection>& childNative, Object^ owner) : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
#ifdef HANDLE
	_phSabrInterpolatedSmileSection = NULL;
#endif
	_ppSabrInterpolatedSmileSection = &childNative;
    _ppSmileSection = new boost::shared_ptr<QuantLib::SmileSection> (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
}
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (QuantLib::SabrInterpolatedSmileSection& childNative, Object^ owner) : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
#ifdef HANDLE
	_phSabrInterpolatedSmileSection = NULL;
#endif
	_ppSabrInterpolatedSmileSection = new boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection> (&childNative);
    _ppSmileSection = new boost::shared_ptr<QuantLib::SmileSection> (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
    _SabrInterpolatedSmileSectionOwner = owner;
    _SmileSectionOwner = owner;
}

Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (CSabrInterpolatedSmileSection^ copy) : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
#ifdef HANDLE
	_phSabrInterpolatedSmileSection = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppSabrInterpolatedSmileSection = new boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection> (copy->GetShared());
        _ppSmileSection = new boost::shared_ptr<QuantLib::SmileSection> (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
    }
}
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (System::Type^ t) : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
#ifdef HANDLE
	_phSabrInterpolatedSmileSection = NULL;
#endif
	if (!t->IsSubclassOf(CSabrInterpolatedSmileSection::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (QuantLib::Handle<QuantLib::SabrInterpolatedSmileSection>& childNative, Object^ owner)  : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
	_phSabrInterpolatedSmileSection = &childNative;
	_ppSabrInterpolatedSmileSection = &static_cast<boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection>>(childNative.currentLink());
    _ppSmileSection = new boost::shared_ptr<QuantLib::SmileSection> (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
    _SabrInterpolatedSmileSectionOwner = owner;
}
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (QuantLib::Handle<QuantLib::SabrInterpolatedSmileSection> childNative)  : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
	_phSabrInterpolatedSmileSection = &childNative;
	_ppSabrInterpolatedSmileSection = &static_cast<boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection>>(childNative.currentLink());
    _ppSmileSection = new boost::shared_ptr<QuantLib::SmileSection> (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::CSabrInterpolatedSmileSection (QuantLib::SabrInterpolatedSmileSection childNative)  : CSmileSection(CSabrInterpolatedSmileSection::typeid)
{
#ifdef HANDLE
	_phSabrInterpolatedSmileSection = NULL;
#endif
	_ppSabrInterpolatedSmileSection = new boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection> (new QuantLib::SabrInterpolatedSmileSection (childNative));
    _ppSmileSection = new boost::shared_ptr<QuantLib::SmileSection> (boost::dynamic_pointer_cast<QuantLib::SmileSection> (*_ppSabrInterpolatedSmileSection));
}
#endif

Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::~CSabrInterpolatedSmileSection ()
{
    if (_ppSabrInterpolatedSmileSection != NULL)
    {
	    delete _ppSabrInterpolatedSmileSection;
        _ppSabrInterpolatedSmileSection = NULL;
    }
}
Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::!CSabrInterpolatedSmileSection ()
{
    if (_ppSabrInterpolatedSmileSection != NULL)
    {
	    delete _ppSabrInterpolatedSmileSection;
    }
}
QuantLib::SabrInterpolatedSmileSection& Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::GetReference ()
{
    if (_ppSabrInterpolatedSmileSection == NULL) throw gcnew NativeNullException ();
	return **_ppSabrInterpolatedSmileSection;
}
boost::shared_ptr<QuantLib::SabrInterpolatedSmileSection>& Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::GetShared ()
{
    if (_ppSabrInterpolatedSmileSection == NULL) throw gcnew NativeNullException ();
	return *_ppSabrInterpolatedSmileSection;
}
QuantLib::SabrInterpolatedSmileSection* Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::GetPointer ()
{
    if (_ppSabrInterpolatedSmileSection == NULL) throw gcnew NativeNullException ();
	return &**_ppSabrInterpolatedSmileSection;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::SabrInterpolatedSmileSection>& Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::GetHandle ()
{
	if (_phSabrInterpolatedSmileSection == NULL)
	{
		_phSabrInterpolatedSmileSection = new Handle<QuantLib::SabrInterpolatedSmileSection> (*_ppSabrInterpolatedSmileSection);
	}
	return *_phSabrInterpolatedSmileSection;
}
#endif
bool Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::HasNative () 
{
	return (_ppSabrInterpolatedSmileSection != NULL);
}

Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::Alpha::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->alpha ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::AtmLevel::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->atmLevel ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::Beta::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->beta ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Math::Optimization::EndCriteria::TypeEnum Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::EndCriteria::get ()
{
    try
    {
    	QuantLib::EndCriteria::Type _rv = (QuantLib::EndCriteria::Type)(*_ppSabrInterpolatedSmileSection)->endCriteria ( );   
        QL::Math::Optimization::EndCriteria::TypeEnum _nrv = (QL::Math::Optimization::EndCriteria::TypeEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::MaxError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->maxError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::MaxStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->maxStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::MinStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->minStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::Nu::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->nu ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::PerformCalculations::get ()
{
    try
    {
    	(*_ppSabrInterpolatedSmileSection)->performCalculations ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::Rho::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->rho ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::RmsError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->rmsError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppSabrInterpolatedSmileSection)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::VarianceImpl (Double strike)
{
    try
    {
        QuantLib::Rate _strike = (QuantLib::Rate)ValueHelper::Convert (strike);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppSabrInterpolatedSmileSection)->varianceImpl ( _strike );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection::VolatilityImpl (Double strike)
{
    try
    {
        QuantLib::Rate _strike = (QuantLib::Rate)ValueHelper::Convert (strike);
    	QuantLib::Volatility _rv = (QuantLib::Volatility)(*_ppSabrInterpolatedSmileSection)->volatilityImpl ( _strike );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection_Factory::Create (DateTime optionDate, Double forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Double atmVolatility, Cephei::IVector<Double>^ vols, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc)
{
    return gcnew CSabrInterpolatedSmileSection ( optionDate,  forward,  strikes,  hasFloatingStrikes,  atmVolatility,  vols,  alpha,  beta,  nu,  rho,  isAlphaFixed,  isBetaFixed,  isNuFixed,  isRhoFixed,  vegaWeighted,  endCriteria,  method,  dc);
}
Cephei::QL::Termstructures::Volatility::ISabrInterpolatedSmileSection^ Cephei::QL::Termstructures::Volatility::CSabrInterpolatedSmileSection_Factory::Create (DateTime optionDate, Cephei::QL::IQuote^ forward, Cephei::IVector<Double>^ strikes, Boolean hasFloatingStrikes, Cephei::QL::IQuote^ atmVolatility, Cephei::IVector<Cephei::QL::IQuote^>^ volHandles, Double alpha, Double beta, Double nu, Double rho, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isAlphaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isBetaFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isNuFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ isRhoFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc)
{
    return gcnew CSabrInterpolatedSmileSection ( optionDate,  forward,  strikes,  hasFloatingStrikes,  atmVolatility,  volHandles,  alpha,  beta,  nu,  rho,  isAlphaFixed,  isBetaFixed,  isNuFixed,  isRhoFixed,  vegaWeighted,  endCriteria,  method,  dc);
}
